<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Hordesxml
{
	private	$CI;
	private $xml	= NULL;
	private	$key	= NULL;
	
	private $siteKey = "44a6d28ce190359d8a08bca2153a5bb2";
	
	// $data['owner']['nickname]
	// $data['owner']['avatar']
	// $data['owner']['id']
	private	$data;
	
	
	private	$root_node 		= "hordes";
	private $header_node	= "headers";
	private $owner_node		= "owner";
	private $citizen_node	= "citizen";
	
	private $error_node		= "error";
	
	private $owner_path;
	private $error_path;
	
	
	public function __construct()
	{
		$this->CI = get_instance();
		
		$this->owner_path = '/'.$this->root_node.'/'.$this->header_node.'/'.$this->owner_node.'/'.$this->citizen_node;
		$this->error_path = '/'.$this->root_node.'/'.$this->error_node;
	}
	
	public function loadXml( $inKey )
	{
		$url = "http://www.hordes.fr/xml?k=".$inKey.";sk=".$this->siteKey;
		if( !$xml = simplexml_load_file( "http://www.hordes.fr/xml?k=c825e1454807c94f80ccf6f3411873d218a1072;sk=44a6d28ce190359d8a08bca2153a5bb2" ) )
			return false;

		$this->key = $inKey;	
		$this->xml = $xml;
		
		
		if( !$owner_nodes = $xml->xpath( $this->owner_path ) )
			return false;
		
		$this->data['owner']['nickname']= $owner_nodes[0]['name'];
		$this->data['owner']['avatar']	= $owner_nodes[0]['avatar'];
		$this->data['owner']['id']		= $owner_nodes[0]['id'];
			
		
		if( $error_nodes = $xml->xpath( $this->error_path ) )
		{
			$this->data['error'] = $error_nodes[0]['code'];
			return $this->data;
		}
			
		return $this->data;
	}
	
}

/* End of file layout.php */
/* Location: ./application/libraries/layout.php */ ?>